//
//  SettingViewController.m
//  SafPay
//
//  Created by 贺庆博 on 2018/6/19.
//  Copyright © 2018年 ebo. All rights reserved.
//

#import "SettingViewController.h"
#import "SettingCell.h"
#import "ChangePhoneController.h"
#import "CopySafeWordController.h"
#import "SetPwdController.h"
#import "SettingModel.h"
#import "VerPwdController.h"
@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    BOOL isBind;
    BOOL isCopy;
}
@property (strong,nonatomic) UITableView *tableView;
@property (strong,nonatomic) NSMutableArray *arrDS;
@end

@implementation SettingViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([AccountTools shared].currentAccount.phoneNumber) {
        SettingModel*model = self.arrDS[0];
        model.right = [AccountTools shared].currentAccount.phoneNumber?:@"";
        isBind = YES;
    }
    if ([AccountTools shared].currentAccount.isCopy) {
        SettingModel*model = self.arrDS[2];
        model.right = [AccountTools shared].currentAccount.isCopy?@"已备份":@"尚未备份";
        isCopy = YES;
    }
    [self.tableView reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"设置";
    [self initUI];
    // Do any additional setup after loading the view.
}
- (void)initUI
{
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(8, 0, 0, 0));
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [UITableView new];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerNib:[UINib nibWithNibName:@"SettingCell" bundle:nil] forCellReuseIdentifier:@"SettingCell"];
    }
    return _tableView;
}
- (NSMutableArray *)arrDS
{
    if (!_arrDS) {
        _arrDS = [NSMutableArray array];
        NSArray *arr = @[@{@"left":@"我的手机",@"right":[AccountTools shared].currentAccount.phoneNumber?:@""},
                         @{@"left":@"修改密码",@"right":@""},
                         @{@"left":@"备份助记词",@"right":@"尚未备份"}
                         ];
        __weak typeof (NSMutableArray *)weakArr = _arrDS;
        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            SettingModel *model = [SettingModel new];
            [model setValuesForKeysWithDictionary:obj];
            [weakArr addObject:model];
        }];
    }
    return _arrDS;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrDS.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.model = self.arrDS[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            {
                ChangePhoneController *vc = [ChangePhoneController new];
                vc.isBind = isBind;
                [self.navigationController pushViewController:vc animated:YES];
            }
            break;
        case 1:
            {
//                SetPwdController *vc = [SetPwdController new];
//                vc.isChange=YES;
//                vc.isSetting=YES;
//                [self.navigationController pushViewController:vc animated:YES];
                VerPwdController *vc=[VerPwdController new];
                vc.isSetting=YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            break;
        case 2:
            {
                if (isCopy) {
                    return;
                }
                CopySafeWordController *vc = [CopySafeWordController new];
                vc.keyWord=[AccountTools shared].currentAccount.keyWord;
                vc.isSetting=YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            break;
        default:
            break;
    }
}



@end
